package view.room;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import constants.RoomConstants;
import entity.Room;

public class RoomDialog extends JDialog{

	JTextField tfRoomId;
	JTextField tfRoomName;
	JComboBox  cbRoomType;
	JTextField tfCost;
	JTextArea taInfo;
	JButton btAdd;
	JButton btCancel;
	Room room;
	public RoomDialog(JFrame parent, String title, Room room){
		super(parent, title, true);
		this.room = room;
		setSize(600, 300);
		setLocationRelativeTo(parent);
		setResizable(false);
		setLayout(new GridBagLayout());
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.fill = GridBagConstraints.HORIZONTAL;
		gbc.insets = new Insets(10, 10, 10, 10);
		int y = 0;
		gbc.weightx = 1.0;
//		gbc.weighty = 1.0;
		
		gbc.gridy = y++;
			gbc.weightx = 0;
			gbc.gridx = 0; add(new JLabel("Mã phòng"), gbc);
			gbc.weightx = 1.0;
			gbc.gridx = 1; add(tfRoomId = new JTextField(30), gbc);
			gbc.weightx = 0;
			gbc.gridx = 2; add(new JLabel("Tên phòng"), gbc);
			gbc.weightx = 1.0;
			gbc.gridx = 3; add(tfRoomName = new JTextField(30), gbc);
		gbc.gridy = y++;
		gbc.weightx = 0;
			gbc.weightx = 0;
			gbc.gridx = 0; add(new JLabel("Loại phòng"), gbc);
			gbc.weightx = 1.0;
			gbc.gridx = 1; add(cbRoomType = new JComboBox(RoomConstants.TYPE_NAME), gbc);
			gbc.weightx = 0;
			gbc.gridx = 2; add(new JLabel("Giá phòng"), gbc);
			gbc.weightx = 1.0;
			gbc.gridx = 3; add(tfCost = new JTextField(30), gbc);
		gbc.gridy = y++;
			gbc.weightx = 0;
			gbc.gridx = 0; add(new JLabel("Thông tin"), gbc);
			gbc.weightx = 1;
		gbc.gridy = y++;
			gbc.gridx = 0;
			gbc.weighty = 1.0;
			gbc.fill = GridBagConstraints.BOTH;
			gbc.gridwidth = 4; add(taInfo = new JTextArea(30, 10), gbc);
			gbc.gridwidth = 1;
			gbc.weighty = 0;
			gbc.fill = GridBagConstraints.HORIZONTAL;
			
		gbc.gridy = y++;
			gbc.anchor = GridBagConstraints.PAGE_END;
			
			JPanel jpButton = new JPanel();
			jpButton.add(btAdd = new JButton("Thêm phòng"));
			jpButton.add(btCancel = new JButton("Hủy bỏ"));
			btAdd.addActionListener(new ButtonHandler());
			btCancel.addActionListener(new ButtonHandler());
			gbc.gridx = 3; add(jpButton, gbc);
	}
	
	class ButtonHandler implements ActionListener{
		public void actionPerformed(ActionEvent event){
			if (event.getSource() == btAdd){
				
			}else if (event.getSource() == btCancel){
				dispose();
			}
		}
	}
	public Room showAndReturn(){
		setVisible(true);
		return room;
	}
}
